<?php
include '../../../wp-blog-header.php';
require_once 'excel_reader2.php';
$data = new Spreadsheet_Excel_Reader("delivery-chef.xls");
$api = new PodAPI();
echo "<pre>";
$excel_data = $data->sheets['0']['cells'];
$excel_columns = array_shift($excel_data);
//print_r($excel_data);
//exit();

foreach($excel_data as $key=>$value){
  $columns_deal['name'] = pods_sanitize(ucwords(strtolower($value[4].': '.$value[1])));
  $columns_deal['camp_link'] = sanitize_title($columns_deal['name']);
  
  $deal = new Pod('deal');
  $deal->page=1;
  $deal->search=false;
  $where = "t.camp_link = '".$columns_deal['camp_link']."' AND t.sale = 1 AND deal_provider.id='258'";
  $deal->findRecords('id DESC', 1,$where);
  $dealsFound = $deal->getTotalRows();
  
  if($dealsFound == 1)
  {
    while($deal->fetchRecord()){
      $id = $deal->get_field('id');
      echo $id."<br />";
      $latlng = $value[11].','.$value[12];
      //echo $latlng."<br /><br />";
      $columns_deal['latlng'] = $latlng;
      $params = array('datatype' => 'deal','tbl_row_id'=>$id, 'columns' => $columns_deal);
      $api->save_pod_item($params);
    }
    /*
    echo '<pre>';
    print_r($params);
    echo '</pre>';
    exit();
    */
  }
  
}